package com.example.controller.admin;

import com.example.common.Result;
import com.example.entity.DTO.DepartmentDetailDTO;
import com.example.entity.Department;
import com.example.service.admin.DepartmentService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class DepartmentController {
    @Resource
    private DepartmentService departmentService;

    /**
     * 根据名称模糊查询学院详细信息
     */
    @GetMapping("/selectAllDept")
    public Result selectAllDept(@RequestParam(defaultValue = "") String name) {
        List<DepartmentDetailDTO> departmentDetailDTOS = departmentService.selectAllDept(name);
        return Result.success(departmentDetailDTOS);
    }

    /**
     * 添加学院
     */
    @PostMapping("/addDept")
    public Result addDept(@RequestBody Department department) {
        departmentService.addDept(department);
        return Result.success();
    }

    /**
     * 更新学院信息
     */
    @PutMapping("/updateDept")
    public Result updateDept(@RequestBody Department department) {
        departmentService.updateDept(department);
        return Result.success();
    }

    /**
     * 删除学院
     */
    @DeleteMapping("/deleteDept/{id}")
    public Result deleteDept(@PathVariable Integer id) {
        departmentService.deleteDept(id);
        return Result.success();
    }

    /**
     * 根据名称查询单个学院详细信息
     */
    @GetMapping("/selectDept")
    public Result selectDept(@RequestParam String name) {
        DepartmentDetailDTO departmentDetailDTO = departmentService.selectDept(name);
        return Result.success(departmentDetailDTO);
    }
}
